package org.example.frw.canal.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@ConfigurationProperties(prefix = "canal.mq.consumer.concurrently")
public class TopicConcurrentlySetting {
  
    private final Map<String, Integer> topicconcurrentlysetting = new HashMap<>();

    public Integer getTopicConcurrentlyLevel(String topic) {
        Integer integer = topicconcurrentlysetting.get(topic);
        if(integer == null){
            Integer aDefault = topicconcurrentlysetting.get("default");
            integer = aDefault == null?4:aDefault;
        }
        return integer <= 0 ? 4: integer;
    }  
}